/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pack_servlets;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import pack_gestionarUsuario.RegistrarUsuarioService;

/**
 *
 * @author Fernando
 */
@WebServlet(name = "RegistrarUsuario", urlPatterns = {"/RegistrarUsuario"})
public class RegistrarUsuario extends HttpServlet {

    int registrarUsuarioServiceResult = 0;

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        try {
            String username = (String) request.getParameter("usernamesignup");
            String email = (String) request.getParameter("emailsignup");
            String password = (String) request.getParameter("passwordsignup");
            int cedula = Integer.parseInt(request.getParameter("cedulasignup"));

            try {
                pack_gestionarUsuario.GestionUsuario service = new pack_gestionarUsuario.GestionUsuario();
                pack_gestionarUsuario.GestionUsuarioSoap port = service.getGestionUsuarioSoap();
                // TODO initialize WS operation arguments here
                pack_gestionarUsuario.RegistrarUsuarioService parameters = new RegistrarUsuarioService();
                parameters.setEmail(email);
                parameters.setUsuario(username);
                parameters.setPassword(password);
                parameters.setCedula(cedula);
                // TODO process result here
                pack_gestionarUsuario.RegistrarUsuarioServiceResponse result = port.registrarNuevoUsuario(parameters);
                registrarUsuarioServiceResult = result.getRegistrarUsuarioServiceResult();
                System.out.println("valor de efecto: "+registrarUsuarioServiceResult);
            } catch (Exception ex) {
                // TODO handle custom exceptions here
            }


        } finally {
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
        String respMess = "" + registrarUsuarioServiceResult;
        response.setContentType("text/plain");
        response.setCharacterEncoding("UTF-8");
        response.getWriter().write(respMess);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
